package string;

import org.junit.Test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringDemo6 {

  public static void main(String[] args) {
    String b = "b";
    String a = "a" + b;
    System.out.println("ab" == a); //false
//    System.out.println(new String("ab") == a); //false
//    System.out.println(new String("ab").intern() == a);
//    System.out.println(a.intern() == a);
//    String ab = "ab";
//    System.out.println(a == ab);
  }

  public static final String aa = ")";
  public static final String aa1 = "(";

  public static final String bb = "）";
  public static final String bb1 = "（";

  @Test
  public void test() {

    String format = String.format("%s %s", "上海", "shanghai");
    System.out.println(format);

    String[] ss = {
            "밍스산링(명십삼릉)",
            "七色蝶々園（カラフルバタフライガーデン）",
            "九渓煙樹（ナイン・クリークス・イン・ザ・ミスティーフォレスト）"
    };
    for (String s : ss) {

      if (s.endsWith(aa)) {
        String replacea = replacea(s);
        System.out.println(replacea);
        System.out.println(s.substring(0, s.indexOf(aa1)));
      } else if (s.endsWith(bb)) {
        System.out.println(replaceb(s));
        System.out.println(s.substring(0, s.indexOf(bb1)));
      } else {
      }

    }

  }

  static String replacea(String src) {
    Pattern pattern = Pattern.compile("(?<=\\()[^\\)]+");
    Matcher matcher = pattern.matcher(src);
    if (matcher.find()) {
      return matcher.group(0);
    }
    return "";
  }

  static String replaceb(String end) {
    Pattern p = Pattern.compile("(?<=（)[^）]+");
    Matcher matcher = p.matcher(end);
    if (matcher.find()) {
      return matcher.group(0);
    }
    return "";
  }


  public void test3() {

  }

}
